import React from 'react';
import axios from 'axios'
import './OrderList.css';
import OrderHistoryData from '../../component/Order/OrderHistoryData/OrderHistoryData';    //第一行显示的订单数据
import OrderSearch from '../../component/Order/OrderSearch/OrderSearch';    //查找订单
import OrderDataList from '../../component/Order/OrderDataList/OrderDataList';   //订单列表
import { message } from 'antd';

class OrderList extends React.Component {
    constructor(props){
        super(props);
        this.state={
            searchData:{},
            orderData:{}
        }
    }
    //改变state值
    changeSearchData=(newData)=>{
        this.setState({
            searchData:newData
        })
    };
    //发起请求获取表格数据
    reqData=()=>{
        axios({
            url:'http://123.57.67.148:3000/mock/195/searchOrder',
            method:'post',
            data:this.state.searchData
        }).then(res=>{
            // console.log(res.data);
            if (res.data.code===200&&res.data.orderData.length>0){
                message.success('查询成功');
                res.data.orderData.filter(item=>{
                    item.key=item.orderId;
                    return item;
                });
                this.setState({
                    orderData:res.data.orderData
                });
                this.showData();
            }else {
                message.error('未找到符合条件的数据');
            }
        })
    };
    //获取子组件列表组件的this
    onRefChild = (ref) => {
        this.child = ref
    };
    //改变表格数据
    showData=()=>{
        this.child.changeData(this.state.orderData)
    };
    render() {
        let mapMethodToProps={
            changeState:this.changeSearchData,
            reqData:this.reqData
        };

        return (
            <div>
            <OrderHistoryData/>
            <OrderSearch {...mapMethodToProps}/>
        <OrderDataList onRefChlid={this.onRefChild}/>
        </div>
    )
    }
}

export default OrderList;